package com.ruoyi.system.service.shopping.impl;

import com.ruoyi.system.domain.shopping.dto.CollectDto;
import com.ruoyi.system.mapper.shopping.CollectMapper;
import com.ruoyi.system.service.shopping.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CollectServiceImpl implements CollectService {
    @Autowired
    private CollectMapper collectMapper;
    @Override
    public List<CollectDto> selectCollectDtoListByUserId(Integer userId) {
        List<CollectDto> collectDtos = collectMapper.selectCollectDtoByUserId(userId);
        return collectDtos;
    }

    @Override
    public Boolean goCollect(Integer userId, Integer productId) {
        // TODO: 2022/9/16   //先判断有没有这个商品
        //1.先判断是否有收藏
        int existCollect = collectMapper.isExistCollect(userId, productId);
        if(existCollect > 0){
            //收藏了 要取消
             return collectMapper.unCollect(userId, productId) > 0;
        } else {
            //未收藏
            return collectMapper.collect(userId,productId) >0 ;
        }
    }

    @Override
    public Boolean isExistCollect(Integer userId, Integer productId) {
        return collectMapper.isExistCollect(userId, productId)>0;
    }
}
